<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="../template.xhtml" 
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:t="http://myfaces.apache.org/tomahawk">

	<ui:define name="conteudo">		
		<a4j:keepAlive beanName="processoBean"/>
		
		<div style="width: 700px">
			<div style="float:left">
				<h2 style="margin: 0px">
					<h:outputText value="#{msg['processo.titulo.cadastrar']}" rendered="#{processoBean.processo.id == null}"/>
					<h:outputText value="#{msg['processo.titulo.editar']}" rendered="#{processoBean.processo.id != null}"/>
				</h2>
			</div>
		</div>
		
		<div style="height: 50px"></div>

		<rich:messages id="mensagemErro" layout="list" style="color: red; font-weight: bold;"/>
	                
		<h:panelGrid columns="2">
		
			<h:outputLabel value="#{msg['processo.npu']}" />
			<h:inputText value="#{processoBean.processo.npu}" size="23"/>
			
			<h:outputLabel value="#{msg['processo.vara']}" />
			<h:selectOneMenu value="#{processoBean.processo.vara}" converter="entityConverter">
				<t:selectItems value="#{processoBean.varas}" var="vara" itemLabel="#{vara.nome}" itemValue="#{vara}" />
			</h:selectOneMenu>

			<h:outputLabel value="#{msg['processo.data']}" />
			<rich:calendar inputSize="10" value="#{processoBean.processo.data}" datePattern="#{msg['geral.formato.data']}"/>
			
		</h:panelGrid>

		<div style="height: 10px"></div>

		<h:panelGrid columns="5">
			<h:outputLabel value="#{msg['processo.parte']}" />
			<h:selectOneMenu value="#{processoBean.parte}" converter="entityConverter">
				<t:selectItems value="#{processoBean.partes}" var="parteOTD" itemLabel="#{parteOTD.tipoParte == 'PF' ? parteOTD.parte.nome : parteOTD.parte.razaoSocial}" itemValue="#{parteOTD.parte}" />
			</h:selectOneMenu>
			<h:outputLabel value="#{msg['processo.tipo.parte']}" />
			<h:selectOneMenu value="#{processoBean.tipoParte}" converter="entityConverter">
				<t:selectItems value="#{processoBean.tiposParte}" var="tipoParte" itemLabel="#{tipoParte.descricao}" itemValue="#{tipoParte}" />
			</h:selectOneMenu>
			<a4j:commandButton value="#{msg['geral.adicionar']}" action="#{processoBean.adicionarParteProcesso}" reRender="parteProcesso"/>
		</h:panelGrid>
		
		<rich:dataTable id="parteProcesso" var="parteProcessoOTD" value="#{processoBean.partesProcesso}" width="700px">
			<rich:column width="150px">
				<f:facet name="header">
					<h:outputText value="#{msg['processo.parte']}" />
				</f:facet>
				<h:outputText value="#{parteProcessoOTD.tipoParte == 'PF' ? parteProcessoOTD.parteProcesso.parte.nome : parteProcessoOTD.parteProcesso.parte.razaoSocial}" />
			</rich:column>
			<rich:column width="150px">
				<f:facet name="header">
					<h:outputText value="#{msg['processo.tipo.parte']}"/>
				</f:facet>
				<h:outputText value="#{parteProcessoOTD.parteProcesso.tipoParte.descricao}"/>
			</rich:column>
			<rich:column width="80px">
				<a4j:commandLink action="#{processoBean.removerParteProcesso}" reRender="parteProcesso">
                    <h:outputText value="#{msg['geral.remover']}" />
                    <f:setPropertyActionListener value="#{parteProcessoOTD}" target="#{processoBean.parteProcesso}" />
                </a4j:commandLink>
			</rich:column>
		</rich:dataTable>

		
		<div style="height: 20px"></div>
		
		<div>
			<h:commandButton value="#{msg['geral.salvar']}" action="#{processoBean.salvar}" />
			<h:commandButton value="#{msg['geral.cancelar']}" action="manterProcesso"/>
		</div>		
	</ui:define>
</ui:composition>